EmptyDroplets (FDR <= 0.1) + scDblFindersetwd("/media/jacopo/Elements/re_align/MM/PRJNA723584/SAMN18822749/SRR14295362/")
# Load the libraries (from Sarah script + biomart)
library(tidyverse) # packages for data wrangling, visualization etc
library(Seurat) # scRNA-Seq analysis package
library(clustree) # plot of clustering tree
library(ggsignif) # Enrich your 'ggplots' with group-wise comparisons
library(clusterProfiler) #The package implements methods to analyze and visualize functional profiles of gene and gene clusters.
library(org.Hs.eg.db) # Human annotation package neede for clusterProfiler
library(ggrepel) # extra geoms for ggplo2
library(patchwork) #multiplots
library(reticulate)
Load and do the QC for the cellranger data
#list.files(".")
dat <- Read10X(data.dir ="./out/counts_filtered/")
dat <- CreateSeuratObject(dat) # Create the seurat object from the 10x data
kb.initial <- dat@assays[["RNA"]]@counts@Dim[[2]]
cat("Initial number of cells:", kb.initial,
"\nNumber of genes:", dat@assays[["RNA"]]@counts@Dim[[1]])
## Initial number of cells: 9940
## Number of genes: 36601
Empty cells were already filtered, check for % mt RNA and death markers:
# first calculate the mitochondrial percentage for each cell
dat$percent_mt <- PercentageFeatureSet(dat, pattern="^MT.")
# make violin plots
mt_rna = 10
max_counts = 40000
# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
# Check some feature-feature relationships
# % mt RNA vs n Counts, n Features vs n Counts
VlnPlot(dat, features = c("nCount_RNA", "nFeature_RNA", "percent_mt")) + geom_hline(yintercept=mt_rna, linetype = "dotted")
plot1 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "percent_mt")
plot1 <- plot1 + geom_hline(yintercept=mt_rna, linetype = "dotted")
plot2 <- FeatureScatter(dat, feature1 = "nCount_RNA", feature2 = "nFeature_RNA")
plot2 <- plot2 + geom_vline(xintercept = max_counts, linetype = "dotted")
plot1
plot2
## cells retained by mt RNA content ( 10 %): 9369
## percentage of retained cells: 94.26 %
## cells retained by counts ( 40000 ): 9336
## percentage of retained cells: 93.92 %
Check the distribution of the cells with low counts and control death markers:
min_counts = 400
hist(dat@meta.data$nCount_RNA, breaks = 100, xlab = "Counts")
hist(dat@meta.data$nCount_RNA, breaks = 1000, xlab = "Counts", xlim = c(0,5000))
hist(dat@meta.data$nCount_RNA, breaks = 10000, xlab = "Counts", xlim = c(0,1000))
abline(v=min_counts, col="red", lty = 3)
The evident peak of cells with < 200 counts could contain dying
cells.
# Subset the dataset to focus only on those cells with low counts
dat.lowcount <- subset(dat, subset = nCount_RNA < min_counts)
# Get the mean of the counts for each gene and sort them decreasing
meanCounts <- rowMeans(GetAssayData(object = dat.lowcount, slot = 'counts'))
meanCounts <- sort(meanCounts, decreasing = T)
# A boxplot can help to observe the distribution of the means
#boxplot(meanCounts)
# Print the most highly expressed genes
head(meanCounts, 30)
## MT-CO2 VIM GAPDH IGLC2 MT-CO1 EEF1A1 MT-CO3 MT-ATP6
## 2.1280938 1.6695614 1.5931394 1.5149805 1.4554928 1.3000434 1.2570560 1.2336083
## MALAT1 RPL10 FTH1 RPLP1 RPS18 TMSB10 B2M IGHA1
## 1.2227529 1.1610942 1.1458967 1.0030395 0.9748155 0.9531046 0.9209726 0.9079462
## S100A6 RPS3 RPS12 RPL13 RPL41 RPS4X MT-CYB MT2A
## 0.9009987 0.8962223 0.8818932 0.8814590 0.8792879 0.8675640 0.8028658 0.7954842
## RPL19 TMSB4X RPS24 RPS23 FTL RPL39
## 0.7815892 0.7611811 0.7481546 0.7320886 0.7047330 0.6925749
## cells retained by counts ( 400 ): 7032
## percentage of retained cells: 70.74 %
dir.create("result")
saveRDS(dat, file = "./result/SAMN18822749_clean_QC.Rds")
#Normalize
dat <- NormalizeData(dat)
# Find the first 4000 variabe features
dat <- FindVariableFeatures(dat, selection.method = "vst", nfeatures = 4000)
Set mean expression to 0 and variance across 1 to avoid highly expressed genes drive the forwarding analyses. Since negative expression is meaningless, scaled data are useful only for UMAP and clustering
# scale data, the scaled data are saved in:
# dat[["RNA"]]@scale.data
all.genes <- rownames(dat)
dat <- ScaleData(dat, vars.to.regress = c("percent_mt","nCount_RNA"))
dat <- RunPCA(dat, features = VariableFeatures(object = dat), verbose = F, seed.use = 1)
print(dat[["pca"]], dims = 1:5, nfeatures = 5)
## PC_ 1
## Positive: IGHA1, HERPUD1, IGLV3-21, KRT8, LAMP5
## Negative: TYMS, STMN1, HMGB2, TK1, TUBA1B
## PC_ 2
## Positive: MTDH, LY6E, AZGP1, FKBP11, HSPD1
## Negative: CD74, UCP2, TMSB4X, RPS4Y1, ARHGDIB
## PC_ 3
## Positive: TMSB4X, COTL1, CD52, PTPRC, ITGB2
## Negative: IGHA1, MZB1, HBD, HBB, AHSP
## PC_ 4
## Positive: TFF3, MYH7, LINC00665, MYH6, CD9
## Negative: LINC01287, IFI27, XAF1, PCAT19, PCDH20
## PC_ 5
## Positive: AHSP, HBA1, CA1, HBA2, HBB
## Negative: HSPA5, PDIA6, SDF2L1, LAMP5, HGF
UMAP is a graph-based method of clustering. The first step in this process is to construct a KNN graph based on the euclidean distance in PCA space:
dat <- FindNeighbors(dat, dims = 1:20)
The graph now can be used as input for the function
runUMAP()
dat <- RunUMAP(dat, dims = 1:20, seed.use = 1)
DimPlot(dat, reduction = 'umap', seed = 1)
## QC metrics
## markers